package com.lavida.project.system.attendance.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.ibatis.annotations.Update;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ResourceProperties.Content;
import org.springframework.stereotype.Service;

import com.github.pagehelper.util.StringUtil;
import com.lavida.common.utils.DateUtils;
import com.lavida.common.utils.ExcelReaderutil;
import com.lavida.project.system.attendance.domain.Attendances;
import com.lavida.project.system.attendance.mapper.AttendanceMapper;



@Service
public class AttendanceServiceimpl implements AttendanceService{
	@Autowired
	private AttendanceMapper attendanceMapper;
	
	@Autowired
    private static Logger logger = Logger.getLogger(AttendanceServiceimpl.class.getName()); // 日志打印类

    private static final String XLS = "xls";
    private static final String XLSX = "xlsx";

	@Override
	public List<Attendances> selectAttendance(Attendances attendance,String fromtime,String totime) {
		// TODO Auto-generated method stub
		return attendanceMapper.selectAttendance(attendance, fromtime, totime);
	}
	@Override
	public long insertAttendance(String fileName) throws Exception {
		List<Attendances> parsedResult = readExcel(fileName);
		System.out.println(fileName);
		System.out.println(parsedResult.toString());
		long number =0;
		for(Attendances attendance : parsedResult) {
			attendanceMapper.insertAttendance(attendance);
			System.out.println(number);
			number = number++;
		}
		System.out.println(number);
		return number;
	}
	/**
     * 根据文件后缀名类型获取对应的工作簿对象
     * @param inputStream 读取文件的输入流
     * @param fileType 文件后缀名类型（xls或xlsx）
     * @return 包含文件数据的工作簿对象
     * @throws IOException
     */
    public static Workbook getWorkbook(InputStream inputStream, String fileType) throws IOException {
        Workbook workbook = null;
        if (fileType.equals(XLS)) {
            workbook = new HSSFWorkbook(inputStream);
        } else if (fileType.equals(XLSX)) {
            workbook = new XSSFWorkbook(inputStream);
        }
        return workbook;
    }

    /**
     * 读取Excel文件内容
     * @param fileName 要读取的Excel文件所在路径
     * @return 读取结果列表，读取失败时返回null
     */
    public static List<Attendances> readExcel(String fileName) {

        Workbook workbook = null;
        FileInputStream inputStream = null;

        try {
            // 获取Excel后缀名
            String fileType = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
            // 获取Excel文件
            File excelFile = new File(fileName);
            if (!excelFile.exists()) {
                logger.warn("指定的Excel文件不存在！");
                return null;
            }

            // 获取Excel工作簿
            inputStream = new FileInputStream(excelFile);
            workbook = getWorkbook(inputStream, fileType);

            // 读取excel中的数据
            List<Attendances> resultDataList = parseExcel(workbook);

            return resultDataList;
        } catch (Exception e) {
            System.out.println(("解析Excel失败，文件名：" + fileName + " 错误信息：" + e.getMessage()));
            return null;
        } finally {
            try {
                if (null != workbook) {
                    workbook.close();
                }
                if (null != inputStream) {
                    inputStream.close();
                }
            } catch (Exception e) {
                System.out.println("关闭数据流出错！错误信息：" + e.getMessage());
                return null;
            }
        }
    }

    /**
     * 解析Excel数据
     * @param workbook Excel工作簿对象
     * @return 解析结果
     */
    private static List<Attendances> parseExcel(Workbook workbook) {
       List<Attendances> resultDataList = new ArrayList<>();
       workbook.getNumberOfSheets();
        // 解析sheet
        for (int sheetNum = 0; sheetNum <workbook.getNumberOfSheets(); sheetNum++) {
            Sheet sheet = workbook.getSheetAt(sheetNum);
            // 校验sheet是否合法
            if (sheet == null || !sheet.getSheetName().equals("月度汇总")) {
                continue;
            }

            // 获取第一行数据
            int firstRowNum = sheet.getFirstRowNum();
            Row firstRow = sheet.getRow(firstRowNum);
            String firstTime = "";
            if (null == firstRow) {
                logger.warn("解析Excel失败，在第一行没有读取到任何数据！");
            }else {
            	System.out.println("+++++++++++++++++++++++++++"+firstRow.toString());
            	Cell fCell = firstRow.getCell(0);
            	String times = fCell.getStringCellValue();
            	Pattern pattern = Pattern.compile("[0-9]{4}[-][0-9]{1,2}[-][0-9]{1,2}");
        	    Matcher matcher = pattern.matcher(times);
        	    String dateStr = null;
        	    if(matcher.find()){
        	      dateStr = matcher.group(0);
        	    }
        	    
        	    firstTime =dateStr.toString();
            }
            System.out.println("-------------------------"+firstTime);
            // 解析每一行的数据，构造数据对象
            int rowStart = firstRowNum + 4;
            int rowEnd = sheet.getPhysicalNumberOfRows();
            for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
                Row row = sheet.getRow(rowNum);
                if (null == row) {
                    continue;
                }

                Attendances resultData = convertRowToData(row,firstTime);
                if (null == resultData) {
                    logger.warn("第 " + row.getRowNum() + "行数据不合法，已忽略！");
                    continue;
                }
                resultDataList.add(resultData);
            }
        }

        return resultDataList;
    }

    /**
     * 将单元格内容转换为字符串
     * @param cell
     * @return
     */
    private static String convertCellValueToString(Cell cell) {
        if(cell==null){
            return null;
        }
        String returnValue = null;
        switch (cell.getCellTypeEnum()) {
            case NUMERIC:   //数字
                Double doubleValue = cell.getNumericCellValue();
                // 格式化科学计数法，取一位整数
                DecimalFormat df = new DecimalFormat("0");
                returnValue = df.format(doubleValue);
                break;
            case STRING:    //字符串
                returnValue = cell.getStringCellValue();
                break;
            case BOOLEAN:   //布尔
                Boolean booleanValue = cell.getBooleanCellValue();
                returnValue = booleanValue.toString();
                break;
            case BLANK:     // 空值
                break;
            case FORMULA:   // 公式
                returnValue = cell.getCellFormula();
                break;
            case ERROR:     // 故障
                break;
            default:
                break;
        }
        return returnValue;
    }
   
    /**
     * 提取每一行中需要的数据，构造成为一个结果数据对象
     *
     * 当该行中有单元格的数据为空或不合法时，忽略该行的数据
     *
     * @param row 行数据
     * @return 解析后的行数据对象，行数据错误时返回null
     */
    private static Attendances convertRowToData(Row row,String firstTime) {
       Attendances resultData = new Attendances();
       try {
    	  System.out.println(firstTime+"+++++++++++++++++---------");
    	   /**
    	    * HR系统表格。      原始打卡机考勤统计表
			工时=出勤天数+外出天数）*8
			加班=？
			旷工=（旷工迟到天数+旷工天数）*8
			年假=年假天数*8
			病假 改成 产假，产检假
			事假=事假
			
			迟到次数=迟到次数
			迟到时间（30分钟以内）=迟到次数- 【后面两个 】
			迟到时间（30-60分钟）=严重迟到次数 
			迟到时间（60分钟以上）=旷工迟到
			
			早退次数=早退次数
    	    */
	       Cell cell;
	       int cellNum = 0;
	       //获取名字
	       cell = row.getCell(cellNum++);
	       String name = convertCellValueToString(cell);
	       System.out.println(name+"    ");
	      if (null == name || "".equals(name)) {
	    	   resultData.setName("无");
	       } else {
	           resultData.setName(name);
	       }
	       //获取考勤规制
	       cell = row.getCell(cellNum++);
	       String kaoqin = convertCellValueToString(cell);
	       System.out.println(kaoqin+"    ");
	       if (null == name || "".equals(name)) {
	    	   resultData.setKaoqin("暂无");
	       } else {
	    	   resultData.setKaoqin(kaoqin);
	       }
	       //获取部门
	       cell = row.getCell(cellNum++);
	       String dept = convertCellValueToString(cell);
	       System.out.println(dept+"    ");
	       if (null == dept || "".equals(dept)) {
	           resultData.setDept(null);
	       } else {
	           resultData.setDept(dept);
	       }
	       //获取工号
	       cell = row.getCell(cellNum++);
	       String job_id = convertCellValueToString(cell);
	       System.out.println(job_id+"    ");
	       if (null == job_id || "".equals(job_id)) {
	           resultData.setJob_id("暂无");
	       } else {
	           resultData.setJob_id(job_id);
	       }
	       cell = row.getCell(cellNum++);
	       String userId = convertCellValueToString(cell);
	       System.out.println(userId);
	       	//获取出勤天数
	       	cell = row.getCell(cellNum++);
	       	String chuqin = convertCellValueToString(cell);
	       	if (chuqin==null ||chuqin.equals("")) {
				resultData.setChuqin(0.0);;
			}else {
				resultData.setChuqin(Double.parseDouble(chuqin));
			}
	       	System.out.println("chuqin"+chuqin);
	       	//获取休息天数
	       	cell = row.getCell(cellNum++);
	       	String xiuxi = convertCellValueToString(cell);
	       	if (xiuxi==null ||xiuxi.equals("")) {
				resultData.setJiaban(0.0);;
			}else {
				resultData.setXiuxi(Double.parseDouble(xiuxi));;
			}
	       	System.out.println(xiuxi+"    ");
	       	//获取工作时长
	       	cell = row.getCell(cellNum++);
	       	String worktime= convertCellValueToString(cell);
	       	if (worktime==null ||worktime.equals("")) {
				resultData.setWorktime(0+"小时");
			}else {
				resultData.setWorktime(worktime);
			}
	       	System.out.println(worktime+"    ");
	       	//获取迟到次数
	       	cell = row.getCell(cellNum++);
		    String latenumber = convertCellValueToString(cell);
		    System.out.println(latenumber+"    ");
		    if (latenumber==null ||latenumber.equals("")) {
				resultData.setLatenumber(0.0);
			}else {
				  resultData.setLatenumber(Double.parseDouble(latenumber));
			}
	        //获取迟到时长
		    cell = row.getCell(cellNum++);
		    String latethiry = convertCellValueToString(cell);
		    System.out.println(latethiry+"    ");
		    if (latethiry==null || latethiry.equals("")) {
				resultData.setLatethiry(0+"小时");
			}else{
				resultData.setLatethiry(latethiry);
			}
		    
		    //获取严重迟到次数
		    cell = row.getCell(cellNum++);
		    String seriousalate = convertCellValueToString(cell);
		    System.out.println(seriousalate+"    " );
		    if (seriousalate==null || seriousalate.equals("") ||seriousalate=="0") {
				resultData.setSeriouslate(0.0);
			}else {
				 resultData.setSeriouslate(Double.parseDouble(seriousalate));
			}
		    //获取迟到严重时长
		    cell = row.getCell(cellNum++);
		    String seriousatetime = convertCellValueToString(cell);
		    System.out.println(seriousalate+"     ");
		    if (seriousatetime==null || seriousatetime.equals("")) {
				resultData.setSeriouslatetime(0+"");
			}else {
				 resultData.setSeriouslatetime(seriousatetime);
			}
		    //获取旷工迟到天数
		    cell = row.getCell(cellNum++);
		    String kuangglate = convertCellValueToString(cell);
		    System.out.println(kuangglate+"      ");
		    resultData.setKuangglate(Integer.parseInt(kuangglate));
		    //获取早退次数
		    cell = row.getCell(cellNum++);
		    String earlynumber = convertCellValueToString(cell);
		    System.out.println(earlynumber+"        ");
		    if (earlynumber==null || earlynumber.equals("")|| earlynumber =="0") {
				resultData.setEarlynumber(0.0);
			}else {
				 resultData.setEarlynumber(Double.parseDouble(earlynumber));
			}
		    //获取早退时长
		    cell = row.getCell(cellNum++);
		    String earlysixty = convertCellValueToString(cell);
		    System.out.println(earlysixty+"          ");
		    resultData.setEarlysixty(earlysixty);
		    //数据过滤
		    cell = row.getCell(cellNum++);
		    String latesixtsy2 = convertCellValueToString(cell);
		  /*  System.out.println(latesixtsy2+"       ");*/
		    cell = row.getCell(cellNum++);
		    String latesixtsy3 = convertCellValueToString(cell);
		   /* System.out.println(latesixtsy3+"          ");*/
		    //旷工天数
		    cell = row.getCell(cellNum++);
		    String kuanggong = convertCellValueToString(cell);
		    System.out.println(kuanggong+"  旷工     ");
		    if (kuanggong == null || kuanggong.equals("") || kuanggong=="0") {
		    	resultData.setKuanggong(0);
			}else{
				 resultData.setKuanggong(Integer.parseInt(kuanggong));
			}
		    //外出
		    cell = row.getCell(cellNum++);
		    String out = convertCellValueToString(cell);
		    System.out.println(out+"         ");
		    //获取事假
	        cell = row.getCell(cellNum++);
	        String shijia = convertCellValueToString(cell);
	        if (shijia ==null || "".equals(shijia)) {
				resultData.setShijia(0+"");
			}else {
				resultData.setShijia(shijia);
			}
	        //获取产假/产检假
	        cell = row.getCell(cellNum++);
	        String chanjia = convertCellValueToString(cell);
	        System.out.println(chanjia+"    ");
	        cell = row.getCell(cellNum++);
	        String chanjian = convertCellValueToString(cell);
	        System.out.println(chanjian+"      ");
	        int chan = 0;
	        if (null == chanjian|| "".equals(chanjian) ) {
	        	chan = 0;
	        }else {
	        	 chan = Integer.parseInt(chanjian);
			}
	        int chanjia1 = 0;
	        if (null == chanjia|| "".equals(chanjia) ) {
	        	chanjia1 = 0;
	        }else {
	        	 chanjia1 =Integer.parseInt(chanjia);
			}
	        System.out.println("产假："+chanjia1+chan);
	        resultData.setChanjia((chanjia1+chan)+"");
	        cell = row.getCell(cellNum++);
	        String pulu = convertCellValueToString(cell);
	        System.out.println(pulu+"      ");
	       
	        
	        //获取病假
	        resultData.setSick(0+"");
		    //获取年假
		    cell = row.getCell(cellNum++);
	        String review = convertCellValueToString(cell);
	        System.out.println(review);
	        System.out.println("-------------------");
	        if(null == review|| "".equals(review)) {
	        	resultData.setReview(0+"");
	        }else {
	        	 resultData.setReview(review+"");
			}
		  //时间
		    
		   if (null == firstTime|| "".equals(firstTime)) {
		    	Date date1 = DateUtils.parseDate("1890/12/05");
		    	resultData.setDates(date1);
		    	resultData.setYear(DateUtils.dateYear(date1));
		    	resultData.setMonth(DateUtils.dateMonth(date1));
		    }else {	
		    	Date dates = DateUtils.parseDate(firstTime);
		    	resultData.setDates(dates);
		    	resultData.setYear(DateUtils.dateYear(dates));
		    	resultData.setMonth(DateUtils.dateMonth(dates));
		    }
		   
       	}catch (Exception e) {
   		// TODO: handle exception
       		e.printStackTrace();
       	}
	    return resultData;
    }
	@Override
	public long insertAttendances(String fileName) throws Exception{
		// TODO Auto-generated method stub
		List<Attendances> parsedResult = readExcel(fileName);
		System.out.println(fileName);
		System.out.println(parsedResult.toString());
		long number =0;
		for(Attendances attendance : parsedResult) {
			List<Attendances> aList = attendanceMapper.selectAttendances(attendance.getJob_id(), attendance.getDates().toString());
			for(Attendances attendances : aList) {
				if (attendances!=null) {
					
					Double sick =Double.parseDouble(attendances.getSick())+Double.parseDouble(attendance.getSick());
					attendance.setSick(sick+"");
				long atr = 	attendanceMapper.updateAttendancess(attendances);
				System.out.println("修改成功:"+atr+"》》。。。。。。");
				}else {
					attendanceMapper.insertAttendances(attendances);
					System.out.println("修改失败");
				}
			}
			System.out.println(number);
			number = number++;
		}
		System.out.println(number);
		return number;
	}
	/**
	 * 钉钉excel解读
	 *//*
	 public static List<Attendances> readExcels(String fileName) {

	        Workbook workbook = null;
	        FileInputStream inputStream = null;

	        try {
	            // 获取Excel后缀名
	            String fileType = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
	            // 获取Excel文件
	            File excelFile = new File(fileName);
	            if (!excelFile.exists()) {
	                logger.warn("指定的Excel文件不存在！");
	                return null;
	            }

	            // 获取Excel工作簿
	            inputStream = new FileInputStream(excelFile);
	            workbook = getWorkbook(inputStream, fileType);

	            // 读取excel中的数据
	            List<Attendances> resultDataList = parseExcels(workbook);

	            return resultDataList;
	        } catch (Exception e) {
	            System.out.println(("解析Excel失败，文件名：" + fileName + " 错误信息：" + e.getMessage()));
	            return null;
	        } finally {
	            try {
	                if (null != workbook) {
	                    workbook.close();
	                }
	                if (null != inputStream) {
	                    inputStream.close();
	                }
	            } catch (Exception e) {
	                System.out.println("关闭数据流出错！错误信息：" + e.getMessage());
	                return null;
	            }
	        }
	    }
	 *//**
	     * 解析Excel数据
	     * @param workbook Excel工作簿对象
	     * @return 解析结果
	     *//*
	    private static List<Attendances> parseExcels(Workbook workbook) {
	       List<Attendances> resultDataList = new ArrayList<>();
	       workbook.getNumberOfSheets();
	        // 解析sheet
	        for (int sheetNum = 0; sheetNum <workbook.getNumberOfSheets(); sheetNum++) {
	            Sheet sheet = workbook.getSheetAt(sheetNum);
	            // 校验sheet是否合法
	            if (sheet == null || !sheet.getSheetName().equals("月度汇总")) {
	                continue;
	            }

	            // 获取第一行数据
	            int firstRowNum = sheet.getFirstRowNum();
	            Row firstRow = sheet.getRow(firstRowNum);
	            String firstTime = "";
	            if (null == firstRow) {
	                logger.warn("解析Excel失败，在第一行没有读取到任何数据！");
	            }else {
	            	System.out.println("+++++++++++++++++++++++++++"+firstRow.toString());
	            	Cell fCell = firstRow.getCell(0);
	            	String times = fCell.getStringCellValue();
	            	Pattern pattern = Pattern.compile("[0-9]{4}[-][0-9]{1,2}[-][0-9]{1,2}");
	        	    Matcher matcher = pattern.matcher(times);
	        	    String dateStr = null;
	        	    if(matcher.find()){
	        	      dateStr = matcher.group(0);
	        	    }
	        	    
	        	    firstTime =dateStr.toString();
	            }
	            System.out.println("-------------------------"+firstTime);
	            // 解析每一行的数据，构造数据对象
	            int rowStart = firstRowNum + 4;
	            int rowEnd = sheet.getPhysicalNumberOfRows();
	            for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
	                Row row = sheet.getRow(rowNum);
	                if (null == row) {
	                    continue;
	                }

	                Attendances resultData = convertRowToDatas(row,firstTime);
	                if (null == resultData) {
	                    logger.warn("第 " + row.getRowNum() + "行数据不合法，已忽略！");
	                    continue;
	                }
	                resultDataList.add(resultData);
	            }
	        }

	        return resultDataList;
	    }
	    //
	    private static Attendances convertRowToDatas(Row row,String firstTime) {
	        Attendances resultData = new Attendances();
	        try {
	     	  System.out.println(firstTime+"+++++++++++++++++---------");
	 	       Cell cell;
	 	       int cellNum = 0;
	 	       //获取名字
	 	       cell = row.getCell(cellNum++);
	 	       String name = convertCellValueToString(cell);
	 	       System.out.println(name+"    ");
	 	      if (null == name || "".equals(name)) {
	 	    	   resultData.setName("无");
	 	       } else {
	 	           resultData.setName(name);
	 	       }
	 	       //获取考勤规制
	 	       cell = row.getCell(cellNum++);
	 	       String kaoqin = convertCellValueToString(cell);
	 	       System.out.println(kaoqin+"    ");
	 	       if (null == name || "".equals(name)) {
	 	    	   resultData.setKaoqin("暂无");
	 	       } else {
	 	    	   resultData.setKaoqin(kaoqin);
	 	       }
	 	       //获取部门
	 	       cell = row.getCell(cellNum++);
	 	       String dept = convertCellValueToString(cell);
	 	       System.out.println(dept+"    ");
	 	       if (null == dept || "".equals(dept)) {
	 	           resultData.setDept(null);
	 	       } else {
	 	           resultData.setDept(dept);
	 	       }
	 	       //获取工号
	 	       cell = row.getCell(cellNum++);
	 	       String job_id = convertCellValueToString(cell);
	 	       System.out.println(job_id+"    ");
	 	       if (null == job_id || "".equals(job_id)) {
	 	           resultData.setJob_id("暂无");
	 	       } else {
	 	           resultData.setJob_id(job_id);
	 	       }
	 	       
	 	       cell = row.getCell(cellNum++);
	 	       String userId = convertCellValueToString(cell);
	 	       System.out.println(userId);
	 	       	//获取出勤天数
	 	       	cell = row.getCell(cellNum++);
	 	       	String chuqin = convertCellValueToString(cell);
	 	       if (chuqin==null ||chuqin.equals("")) {
	 				resultData.setChuqin(0.0);
	 			}else{
	 				  resultData.setChuqin(Double.parseDouble(chuqin));
	 			}
	 	       	System.out.println(chu+"    ");
	 	       	//获取休息天数
	 	       	cell = row.getCell(cellNum++);
	 	       	String xiuxi = convertCellValueToString(cell);
	 	       if (xiuxi==null ||xiuxi.equals("")) {
	 				resultData.setXiuxi(0.0);
	 			}else {
	 				  resultData.setXiuxi(Double.parseDouble(xiuxi));
	 			}
	 	       	System.out.println(jiaban+"    ");
	 	       	//获取工作时长
	 	       	cell = row.getCell(cellNum++);
	 	       	String worktime= convertCellValueToString(cell);
	 	       	if (worktime==null ||worktime.equals("")) {
	 				resultData.setWorktime(0+"小时");
	 			}else {
	 				resultData.setWorktime(worktime);
	 			}
	 	       	System.out.println(worktime+"    ");
	 	       	//获取迟到次数
	 	       	cell = row.getCell(cellNum++);
	 		    String latenumber = convertCellValueToString(cell);
	 		    System.out.println(latenumber+"    ");
	 		    if (latenumber==null ||latenumber.equals("")) {
	 				resultData.setLatenumber(0.0);
	 			}else {
	 				  resultData.setLatenumber(Double.parseDouble(latenumber));
	 			}
	 	        //获取迟到时长
	 		    cell = row.getCell(cellNum++);
	 		    String latethiry = convertCellValueToString(cell);
	 		    System.out.println(latethiry+"    ");
	 		    if (latethiry==null || latethiry.equals("")) {
	 				resultData.setLatethiry(0+"小时");
	 			}else{
	 				resultData.setLatethiry(latethiry);
	 			}
	 		    
	 		    //获取严重迟到次数
	 		    cell = row.getCell(cellNum++);
	 		    String seriousalate = convertCellValueToString(cell);
	 		    System.out.println(seriousalate+"    " );
	 		    if (seriousalate==null || seriousalate.equals("") ||seriousalate=="0") {
	 				resultData.setSeriouslate(0.0);
	 			}else {
	 				 resultData.setSeriouslate(Double.parseDouble(seriousalate));
	 			}
	 		    //获取迟到严重时长
	 		    cell = row.getCell(cellNum++);
	 		    String seriousatetime = convertCellValueToString(cell);
	 		    System.out.println(seriousalate+"     ");
	 		    if (seriousatetime==null || seriousatetime.equals("")) {
	 				resultData.setSeriouslatetime(0+"");
	 			}else {
	 				 resultData.setSeriouslatetime(seriousatetime);
	 			}
	 		    //获取旷工迟到天数
	 		    cell = row.getCell(cellNum++);
	 		    String kuangglate = convertCellValueToString(cell);
	 		    System.out.println(kuangglate+"      ");
	 		    resultData.setKuangglate(Integer.parseInt(kuangglate));
	 		    //获取早退次数
	 		    cell = row.getCell(cellNum++);
	 		    String earlynumber = convertCellValueToString(cell);
	 		    System.out.println(earlynumber+"        ");
	 		    if (earlynumber==null || earlynumber.equals("")|| earlynumber =="0") {
	 				resultData.setEarlynumber(0.0);
	 			}else {
	 				 resultData.setEarlynumber(Double.parseDouble(earlynumber));
	 			}
	 		    //获取早退时长
	 		    cell = row.getCell(cellNum++);
	 		    String earlysixty = convertCellValueToString(cell);
	 		    System.out.println(earlysixty+"          ");
	 		    resultData.setEarlysixty(earlysixty);
	 		    //数据过滤
	 		    cell = row.getCell(cellNum++);
	 		    String latesixtsy2 = convertCellValueToString(cell);
	 		    System.out.println(latesixtsy2+"       ");
	 		    cell = row.getCell(cellNum++);
	 		    String latesixtsy3 = convertCellValueToString(cell);
	 		    System.out.println(latesixtsy3+"          ");
	 		    //旷工天数
	 		    cell = row.getCell(cellNum++);
	 		    String kuanggong = convertCellValueToString(cell);
	 		    System.out.println(kuanggong+"  旷工     ");
	 		    if (kuanggong == null || kuanggong.equals("") || kuanggong=="0") {
	 		    	resultData.setKuanggong(0);
	 			}else{
	 				 resultData.setKuanggong(Integer.parseInt(kuangglate));
	 			}
	 	        //获取产假/产检假
	 	        cell = row.getCell(cellNum++);
	 	        String chanjia = convertCellValueToString(cell);
	 	        if(chanjia==null || chanjia=="") {
	 	        	resultData.setChanjia(0+"");
	 	        }else {
	 	        	resultData.setChanjia(chanjia+"");
	 	        }
	 	        //时间
	 		   if (null == firstTime|| "".equals(firstTime)) {
	 		    	Date date1 = DateUtils.parseDate("1890/12/05");
	 		    	resultData.setDates(date1);
	 		    	resultData.setYear(DateUtils.dateYear(date1));
	 		    	resultData.setMonth(DateUtils.dateMonth(date1));
	 		    }else {	
	 		    	Date dates = DateUtils.parseDate(firstTime);
	 		    	resultData.setDates(dates);
	 		    	resultData.setYear(DateUtils.dateYear(dates));
	 		    	resultData.setMonth(DateUtils.dateMonth(dates));
	 		    }
	 		   
	        	}catch (Exception e) {
	    		// TODO: handle exception
	        		e.printStackTrace();
	        	}
	 	    return resultData;
	     }*/
		@Override
		public long updateAttendances(Attendances attendances) {
			// TODO Auto-generated method stub
			return attendanceMapper.updateAttendances(attendances);
		}
		@Override
		public Attendances AttendanceById(String job_id) {
			// TODO Auto-generated method stub
			return attendanceMapper.AttendanceById(job_id);
		}
		@Override
		public Attendances AttendanceById(Integer job_id) {
			// TODO Auto-generated method stub
			return null;
		}

}